const Controller = require('egg').Controller;
let arr=['香蕉','苹果','鸭梨']
class Myong extends Controller{
    //get请求
    async index(){
        this.ctx.body=arr;
    }
    //post请求
    async create(){
        let {ctx}=this;
        let data=ctx.request.body;
        console.log(data)
        arr.push(data.text);
        ctx.body='添加成功！';
    }
    //删除delect
    async destroy(){
        let id=this.ctx.params.id;
        arr.splice(id,1);
        this.ctx.body='删除成功！';
    }
    //修改
    async update(){
        let data=this.ctx.request.body;
        let id=this.ctx.params.id;
        arr.splice(id,1,data.text);
        this.ctx.body='修改成功';
    }
    async guo(){
        await this.ctx.render('indec',{
            arr:['香蕉','苹果','鸭梨']
        });
    }
}
module.exports = Myong;